package model

import (
	"github.com/gogf/gf/frame/g"
)

type PageInfo struct {
	Page     int `d:"1"  v:"min:0#分页号码错误" json:"page" form:"page"`               // 分页号码
	PageSize int `d:"10" json:"page_size" form:"page_size"` // 分页数量
}

type GetById struct {
	Id uint `v:"min:1#请输入Id"`
}

func (i *GetById) Condition() g.Map {
	return g.Map{"id": i.Id}
}

type GetByIds struct {
	Ids []int `p:"ids" v:"required|length:1,1000#请输入ids|ids长度为:min到:max位"`
}

func (i *GetByIds) Condition() g.Map {
	return g.Map{"id IN (?)": g.Slice{i.Ids}}
}

type DeleteByIds struct {
	Ids []int `p:"ids" v:"required|length:1,1000#请输入id|id长度为:min到:max位"`
}


type PageResult struct {
	List     interface{} `json:"list"`
	Total    int         `json:"total"`
	Page     int         `json:"page"`
	PageSize int         `json:"pageSize"`
}

func (p *PageInfo) Paginate() (limit, offset int) {
	limit = p.PageSize
	offset = p.PageSize * (p.Page - 1)
	return limit, offset
}
